package com.xuetang9.t9.hotel.mapper;

import com.xuetang9.t9.hotel.beans.ETakeoutOrder;
import com.xuetang9.t9.hotel.mapper.condition.ICondition;
import com.xuetang9.t9.hotel.mapper.sql.impl.TakeoutOrderSql;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * @Classname ETakeoutOrderMapper
 * @Description TODO
 * @Date 2020/3/6 15:49
 * @Created by ASUS
 */
public interface ETakeoutOrderMapper {
    @Insert("insert into e_takeoutorder (orderTime,totalPrice,state,remark) values(#{orderTime},#{totalPrice},#{state},#{remark})")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    int insertOrder(ETakeoutOrder order);

    @Delete("delete from e_takeoutorder where id = #{id}")
    int removeOrder(@Param("id") Long id);

    @Select("select * from e_takeoutorder where id = #{id}")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "id",property = "takeoutFoods",many = @Many(select = "com.xuetang9.t9.hotel.mapper.ETakeoutFoodMapper.queryById"))
    })
    ETakeoutOrder queryById(@Param("id") Long id);

    @Update("update e_takeoutorder set state = '已取餐',takeTime = #{now} where id = #{id}")
    int updateTakeout(@Param("id") Long id,@Param("now") Date nowTime);

    @Select("select * from e_takeoutorder order by orderTime desc")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "id",property = "takeoutFoods",many = @Many(select = "com.xuetang9.t9.hotel.mapper.ETakeoutFoodMapper.queryById"))
    })
    List<ETakeoutOrder> queryAll();

    @Select("select * from e_takeoutorder where state = '待取餐'")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "id",property = "takeoutFoods",many = @Many(select = "com.xuetang9.t9.hotel.mapper.ETakeoutFoodMapper.queryById"))
    })
    List<ETakeoutOrder> queryByNone();

    @Select("select * from e_takeoutorder where state = '已取餐'")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "id",property = "takeoutFoods",many = @Many(select = "com.xuetang9.t9.hotel.mapper.ETakeoutFoodMapper.queryById"))
    })
    List<ETakeoutOrder> queryByTake();


    /**
     * 根据条件查询条件
     * @param condition
     * @return
     */
    @SelectProvider(value = TakeoutOrderSql.class,method = "selectByAll")
    @Results({
            @Result(id = true,column = "id",property = "id"),
            @Result(column = "id",property = "takeoutFoods",many = @Many(select = "com.xuetang9.t9.hotel.mapper.ETakeoutFoodMapper.queryById"))
    })
    List<ETakeoutOrder> selectByAll(@Param("key") ICondition condition);


    /**
     * 根据条件查询总数量
     * @param condition
     * @return
     */
    @SelectProvider(value = TakeoutOrderSql.class,method = "selectByCount")
    Long selectByCount(@Param("key") ICondition condition);



}
